import { customRequest } from "../utils/request";
import { IUser } from "@/store/user";

// 获取好友列表
export interface FriendDto {
  name: string;
}
export const getFriends = (data: FriendDto) => {
  return customRequest<IUser[]>({
    url: "/friendship/list",
    method: "get",
    params: data,
  });
};

// 申请添加好友
export interface addFriendDto {
  username: string;
  reason: string;
}
export const addFriend = (data: addFriendDto) => {
  return customRequest<IUser[]>({
    url: "/friendship/add",
    method: "post",
    data,
  });
};

// 获取好友申请列表
export interface IApply {
  id: number;
  fromUserId: number;
  toUserId: number;
  reason: string;
  status: "Pending" | "Approved" | "Rejected";
  createTime: Date;
  updateTime: Date;
}
export interface IApplyFriendDto {
  fromMe: Array<IApply & { toUser: IUser }>;
  toMe: Array<IApply & { fromUser: IUser }>;
}
export const getFriendApplyList = () => {
  return customRequest<IApplyFriendDto>({
    method: "get",
    url: "/friendship/request_list/",
  });
};

// 同意好友申请
export const agreeFriendApply = (id: number) => {
  return customRequest<string>({
    method: "get",
    url: `/friendship/aggree/${id}`,
  });
};

// 拒绝好友申请
export const rejectFriendApply = (id: number) => {
  return customRequest<string>({
    method: "get",
    url: `/friendship/reject/${id}`,
  });
};
